package com.springapi.service.impl;

import com.springapi.entity.Setting;
import com.springapi.dao.SettingDao;
import com.springapi.service.SettingService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统设置(Setting)表服务实现类
 *
 * @author makejava
 * @since 2025-01-04 16:42:47
 */
@Service("settingService")
public class SettingServiceImpl implements SettingService {
    @Resource
    private SettingDao settingDao;

    @Override
    public List<Setting> findshopsetting(int appid, int shopid) {
        return settingDao.findshopsetting(appid,shopid);
    }

    @Override
    public List<Setting> findshopsettingbyname(int appid, int shopid, String name) {
        return settingDao.findshopsettingbyname(appid,shopid,name);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Setting queryById(Integer id) {
        return this.settingDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param setting 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Setting> queryByPage(Setting setting, PageRequest pageRequest) {
        long total = this.settingDao.count(setting);
        return new PageImpl<>(this.settingDao.queryAllByLimit(setting, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param setting 实例对象
     * @return 实例对象
     */
    @Override
    public Setting insert(Setting setting) {
        this.settingDao.insert(setting);
        return setting;
    }

    /**
     * 修改数据
     *
     * @param setting 实例对象
     * @return 实例对象
     */
    @Override
    public Setting update(Setting setting) {
        this.settingDao.update(setting);
        return this.queryById(setting.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.settingDao.deleteById(id) > 0;
    }
}
